/*
 * @Author: your name
 * @Date: 2021-10-13 15:30:55
 * @LastEditTime: 2021-10-13 15:48:23
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /egg_dome/app/controller/list.js
 */
'use strict';

const Controller = require('egg').Controller;

const list = ['西瓜', '苹果'];

class HomeController extends Controller {

    // get 请求
    async index() {
        const { ctx } = this;
        ctx.body = list;
    }


    // post 请求
    async create() {
        const { ctx } = this;
        const {name} = ctx.request.body;
        list.push(name)
        ctx.body = {
            code: 200,
            msg: '添加成功'
        };
    }

    // delete  /api/21
    async destroy() {
        const { ctx } = this;
        const id = ctx.params.id;
        console.log(id)
        list.splice(id, 1);
        ctx.body = {
            code: 200,
            msg: '删除成功'
        };
    }
}

module.exports = HomeController;
